home *** CD-ROM | disk | FTP | other *** search
/ UNIX Applications & Utilities / UNIX Applications & Utilities.iso / tex / maketxpk.cmd < prev    next >
Encoding:
Text File  |  1995-11-04  |  10.6 KB  |  395 lines

  1. /*    
  2.  
  3. Translated from Piet Tutelaar's Unix shell script 
  4. into Rexx by Sebastian Rahtz, 15.8.92 (spqr@minster.york.ac.uk)
  5.  
  6. last change: 28.12.92
  7.  
  8.    This script file makes a new TeX PK font, because one wasn't
  9.    found.  Parameters are:
  10.  
  11.    name dpi bdpi magnification [[mode] subdir]
  12.  
  13.    `name' is the name of the font, such as `cmr10'.  `dpi' is
  14.    the resolution the font is needed at.  `bdpi' is the base
  15.    resolution, useful for figuring out the mode to make the font
  16.    in.  `magnification' is a string to pass to MF as the
  17.    magnification.  `mode', if supplied, is the mode to use.
  18.  
  19.    Note that this file must execute MetaFont (and then gftopk) or
  20.    ps2pk, and place the result in the correct location for the
  21.    PostScript driver to find it subsequently.  If this doesn't work,
  22.    it will be evident because the program will be invoked over and over again.
  23.  
  24.    If no MetaFont source is available for `name' and the fontname
  25.    starts with a `r' or is available in $TEXCONFIG/adobe then the 
  26.    program tries to find a type1 font. If such a font is located 
  27.    ps2pk will be used to render the font.
  28.  
  29.    Of course, it needs to be set up for your site with regard to paths etc
  30. */
  31.  
  32. PARSE Arg all_args
  33. argc=words(all_args)
  34. if ( argc < 4  | argc > 6 ) then 
  35. do
  36.    say "Usage: maketexpk fontname dpi bdpi magnification [[mode] subdir]"
  37.    exit 1
  38. end
  39.  
  40. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  41. call SysLoadFuncs
  42. os2env='OS2ENVIRONMENT'
  43.  
  44. /* destination of pk files */
  45. DESTDIR='d:\texfonts\pixel.lj'
  46.  
  47. /* Where we look for METAFONT sources */
  48. OLDMFINPUT=value('MFINPUT',,os2env)
  49. if OLDMFINPUT='' then
  50. do
  51.     OLDMFINPUT='d:\emtex\mfinput'
  52. end
  53. MFINPUT=OLDMFINPUT
  54. /* 
  55. look for subdirs to add to path;
  56. should find, eg, cm concrete dc euler pandora punk wasy 
  57. */
  58. call SysFileTree OLDMFINPUT"\*.*",'fam','D'
  59. do i=1 to fam.0
  60.  MFINPUT=MFINPUT';'word(fam.i,5)
  61. end
  62. MFINPUT=value('MFINPUT',MFINPUT,os2env)
  63. MFINPUT=value('MFINPUT',,os2env)
  64. /* say 'search path: ' MFINPUT */
  65.  
  66. /* Where we look for Type1 fonts and AFM files */
  67. T1INPUTS=value('T1INPUTS',,os2env)
  68. if T1INPUTS='' then
  69. do
  70.     T1INPUTS='d:\emtex\ps'
  71.     T1INPUTS=value('T1INPUTS',T1INPUTS,os2env)
  72.     T1INPUTS=value('T1INPUTS',,os2env)
  73. end
  74.  
  75. /* Where we look for dvips stuff */
  76. TEXCONFIG='d:\emtex\ps'
  77.  
  78. listoftype1files=TEXCONFIG'\fontname'
  79.  
  80. /* 
  81.  TEMPDIR needs to be unique for each process because of the possibility
  82.  of simultaneous processes running this script.
  83. */
  84. TEMPDIR=SysTempFileName("d:/tmp/mtpk.???")
  85.  
  86. NAME=word(all_args,1)
  87. DPI=word(all_args,2)
  88. BDPI=word(all_args,3)
  89. MAG=word(all_args,4)
  90. if argc > 4 then 
  91.     MODE=word(all_args,5)
  92. else
  93.    if BDPI = 300   then
  94.       MODE='hplaser'
  95.    else if BDPI = 1270   then
  96.       MODE='linohi'
  97.    else if BDPI = 2540   then
  98.       MODE='linosuper'
  99.    else
  100.     do
  101.       say 'I do not know the mode for ' BDPI
  102.       say 'update this MakeTeXPK script'
  103.       exit 1
  104.     end
  105.  
  106. if argc > 5 then 
  107.     SUBDIR=word(all_args,6) 
  108. else
  109.     SUBDIR=BDPI'dpi'
  110.  
  111.  
  112. PKNAME=NAME'.pk'
  113. DESTDIR=DESTDIR'\'DPI'DPI'
  114.  
  115. say 'making for ' MODE ' in ' DESTDIR SUBDIR 
  116. /*
  117. say 'temporary output file is 'TEMPDIR'\'PKNAME
  118. */
  119. call sysfiletree DESTDIR ,'test', 'OD'
  120. if test.0=0 then
  121.       call SysMkDir DESTDIR
  122. /*
  123. else
  124.       say 'directory' DESTDIR 'exists'
  125. */
  126. destpk=DESTDIR'\'PKNAME
  127. fname = stream(destpk , 'C', 'QUERY EXISTS')
  128. if \ (fname ='') then
  129.   do
  130.      say DESTDIR'\'PKNAME 'already exists!'
  131.     exit 0
  132.   end
  133.  
  134. /* OK, try to make the font by some means */
  135.  
  136. /* first try Adobe Type1 fonts 
  137.  
  138.  What encoding scheme do we use for Type1 text fonts? 
  139.  
  140.  Strip off the first letter and last letters
  141.  and see if that gives us a hint 
  142. */
  143.  
  144. DEF_TEXT_ENCODING=' '
  145. PREFIX=left(NAME,1)
  146. SUFFIX=right(NAME,1)
  147.  
  148. select
  149. when PREFIX='r' then
  150.     do
  151.     VNAME=substr(NAME,2)
  152.     DEF_TEXT_ENCODING=' '
  153.     end
  154. when SUFFIX='0' then
  155.     do
  156.     VNAME=left(NAME,length(NAME)-1)
  157.     DEF_TEXT_ENCODING="-eEC.enc"  /* (Extended Computer Modern) */
  158.     end
  159. otherwise
  160.     VNAME=NAME
  161. end
  162.  
  163. call sysfilesearch VNAME' ',listoftype1files, 'FILE.','C'
  164.  
  165. /* if that succeeded, the variable FILE contains the
  166. matching lines in the file describing the fonts */
  167.  
  168. if rc=3 then
  169. do
  170.    say 'You should install file ' listoftype1files
  171.    exit 0
  172. end
  173. FULLNAME='!'
  174. slant=""
  175. VVNAME=VNAME
  176. if FILE.0>0 then 
  177.    do i=1 to file.0
  178.     if word(file.i,1)=VNAME then 
  179.         do
  180.         FULLNAME=word(file.i,2)
  181.         if words(file.i) > 2 then
  182.             do
  183.             slant="-S "||word(file.i,3)
  184.             VVNAME=left(VNAME,length(VNAME)-1)
  185.             end
  186.         leave
  187.         end
  188.    end
  189. if FULLNAME='!' then  /* failed to locate a name in the list 
  190.  
  191.   Do we have a METAFONT source for this typeface? 
  192. */
  193.   do
  194.     if substr(NAME,1,3)='fmv' then 
  195.             mfname=malvern(NAME)  /* Malvern font */ 
  196.     else
  197.        mfname=syssearchpath('MFINPUT',NAME'.mf')
  198.    say 'Result of MF search: 'mfname
  199.    if mfname='' then
  200.     do
  201.           say 'Sorry, no PostScript font or Metafont font found' 
  202.           exit 1
  203.     end
  204.    job='@mfp \mode:='MODE'; mag:='MAG'; scrollmode; input 'name
  205. /* 
  206. really no need to use a temporary directory, I think, in this environment
  207.  
  208.    curdir=directory()
  209.    call SysMkDir TEMPDIR
  210.    newdir= directory(TEMPDIR)
  211. */
  212.    job
  213.    if substr(NAME,1,3)='fmv' then  /* Malvern font */ 
  214.        x=sysfiledelete(NAME||'.mf')
  215.    GFNAME=NAME'.'DPI
  216. /*   if  (stream( GFNAME, 'C', 'QUERY EXISTS') = '') then
  217.     do
  218.       say 'Metafont failed for some reason on 'GFNAME' ('NAME')'
  219.       exit 1
  220.     end
  221.     */
  222.    '@gftopk' GFNAME PKNAME
  223.    '@copy' PKNAME destpk 
  224.    x=sysfiledelete(GFNAME)
  225.    x=sysfiledelete(PKNAME)  
  226.    x=sysfiledelete(NAME'.log')
  227.    /* x=sysfiledelete(NAME'.tfm')   */
  228.    exit 0
  229.    MFINPUT=value('MFINPUT',OLDMFINPUT,os2env)
  230.  end
  231. else
  232. /*  we have a Type1 font (at any rate, its in the list!) */
  233.    afmname=syssearchpath('T1INPUTS',VVNAME'.afm')
  234.    if afmname='' then
  235.       do
  236.         say 'Failed to find afm file for' VVNAME ' in 'T1INPUTS
  237.         exit 1
  238.       end
  239. /*  If we don't use default AFM encoding then we have to check
  240.    if we can apply this encoding (text fonts only) 
  241. */
  242. ENCODING=DEF_TEXT_ENCODING
  243.    if \ (DEF_TEXT_ENCODING = '')   then
  244.     do
  245.     /* What is encoding scheme that the AFM file uses? */
  246.     call sysfilesearch 'EncodingScheme',afmname, 'FILE.','C'      
  247.     if file.0=0  then
  248.         do
  249.          say afmname': Invalid AFM file! No Encoding line.'
  250.          exit 0
  251.         end
  252.         if length(file.1) > 100 then
  253.         do
  254.          say afmname': Invalid AFM file! Encoding line too long.'
  255.          exit 0
  256.         end
  257.       EXT_END=word(file.1,2)
  258.       select
  259.       when substr(ext_end,1,6)='AdobeS' then ENCODING=DEF_TEXT_ENCODING
  260.       when substr(ext_end,1,3)='ISO' then ENCODING=DEF_TEXT_ENCODING
  261.       otherwise
  262.          ENCODING=''
  263.       end
  264.    end
  265. /*
  266.    if substr(NAME,1,3)='hlc' then 
  267.     do
  268.     ENCODING="-eEC.enc"
  269.     say 'applying EC encoding'
  270.     end
  271. */
  272.    pfbname=syssearchpath('T1INPUTS',VVNAME'.pfa')
  273.    if pfbname='' then
  274.     do
  275.       pfbname=syssearchpath('T1INPUTS',VVNAME'.pfb')
  276.       if pfbname='' then
  277.         do
  278.          say 'Source for font' VVNAME 'not found on path 'T1INPUTS
  279.          exit 1
  280.         end
  281.    end
  282.    job='@ps2pk -X'DPI ENCODING SLANT filespec('name',pfbname) destpk 
  283.    say job
  284.    job
  285. exit 0
  286.  
  287. malvern: procedure
  288. arg fontname
  289. /* Malvern generation
  290. #
  291. #  The font name is of the form
  292. #
  293. #        fmvWVV##        Karl Berry's standard font names
  294. #
  295. #  where W   denotes a weight (one of t, i, l, k, r, d, b, x, c)
  296. #        VV  denotes a "variation" (one of <empty>, rn, re, i, in, ie)
  297. #     ##  is the design size, in points
  298. #
  299. #  or
  300. #    maXXx##            my nonstandard font names
  301. #    
  302. #  where XX is 2 digits giving a style in the tradition of Univers
  303. #        x  is a suffix describing the character set of the font
  304. #     ## is the design size, in points (with p as decimal point)
  305. #
  306. #  Examples:
  307. #
  308. #    fmvr10    ma55a10        Malvern 55 10-pt
  309. #    fmvd10    ma65a10        Malvern 65 demibold 10-pt
  310. #    fmvbix18    ma74a18        Malvern 74 bold extended italic 18-pt
  311. #    fmvric7    ma58a7        Malvern 58 condensed italic 7-pt
  312. #
  313. #  The fmv- fonts all use the Cork encoding.
  314. #
  315. */
  316. weights.=''
  317. weights.1= 'weight = 1/4;'    /* ultra-light */
  318. weights.2= 'weight = 1/2;'    /* extra-light */
  319. weights.3= 'weight = 3/4;'    /* light */
  320. weights.4= 'weight = 7/8;'    /* book */
  321. weights.5= 'weight = 1;'    /* medium */
  322. weights.6= 'weight = 1.5;'    /* demi  */
  323. weights.7= 'weight = 2;'    /* bold  */
  324. weights.8= 'weight = 3;'    /* extra */
  325. weights.9= 'weight = 4;'    /* ultra */
  326.  
  327. weights.t= 'weight = 1/4;'    /* thin [ultra-light] */
  328. weights.i= 'weight = 1/2;'    /* extra-lIght */
  329. weights.l= 'weight = 3/4;'    /* Light */
  330. weights.k= 'weight = 7/8;'    /* booK */
  331. weights.r= 'weight = 1;'    /* Regular */
  332. weights.d= 'weight = 1.5;'     /* Demi */
  333. weights.b= 'weight = 2;'    /* Bold */
  334. weights.x= 'weight = 3;'    /* eXtra */
  335. weights.u= 'weight = 4;'    /* Ultra */
  336.  
  337. styles.=''
  338.  
  339. styles.9='hratio = 0.3;'
  340. styles.0='hratio = 0.3; slant := 1/8; italicness = 1;'
  341. styles.7='hratio = 0.6;'
  342. styles.8='hratio = 0.6; slant := 1/8; italicness = 1;'
  343. styles.5='hratio = 1;'
  344. styles.6='hratio = 1; slant := 1/8; italicness = 1;'
  345. styles.3='hratio = 1.15;'
  346. styles.4='hratio = 1.15; slant := 1/8; italicness = 1;'
  347. styles.1='hratio = 1.30;'
  348. styles.2='hratio = 1.30; slant := 1/8; italicness = 1;'
  349.  
  350. styles.i='italicness = 1; slant := 1/8;'    /* italic */
  351. styles.u='italicness = 1;'         /* vertical italic */
  352. styles.o='slant := 1/8;'            /* oblique */
  353.  
  354. /* Berry's system has expansion after variant rather than before: */
  355. styles.o='hratio = 0.3;'    /* narrow (extra condensed) */
  356. styles.c='hratio = 0.6;'    /* compressed */
  357. styles.x='hratio = 1.15;'    /* expanded */
  358. styles.w='hratio = 1.30;'     /* wide (extra expanded) */
  359.  
  360. /* not used here
  361. -J 's=encoding=0'    # Standard TeX text (like cmr)
  362. -J 'x=encoding=-200'    # Cork (TUGboat 11#4)
  363. -J 'mi=encoding=-1'    # maths (like cmmi)
  364. -J 'sy=encoding=-2'    # symbol (like cmsy)
  365. -J 'ps=encoding=-1000'    # the AdobeStandardEncoding encoding
  366. -J 'so=encoding=-1010'    # the ISOLatin1Encoding encoding
  367.  
  368. #  Malvern encodings:
  369. -J 'a=encoding=1'    # Malvern A (simple letters)
  370. -J 'b=encoding=2'    # Malvern B (strange symbols)
  371. -J 'c=encoding=3'    # Malvern C (composites)
  372. */
  373. rf=reverse(fontname)
  374. parse var rf n1 +1 n2 +1 .
  375. if datatype(n2,'N')=1 then
  376.   size=n2||n1
  377. else
  378.   size=n1
  379. parse var fontname basename (size) .
  380. parse var basename base +3 weight +1 style +1 expansion 
  381. if style\=' ' then
  382.   y=value(style)
  383. else
  384.   y=''
  385. if expansion\=' ' then
  386.   z=value(expansion)
  387. else 
  388.   z=''
  389. x=value(weight)
  390. fontfile=value(fontname)||'.mf'
  391. call lineout fontfile,'font_size 'size'pt#; 'weights.x styles.y styles.z 'input maltex;bye.'
  392. call lineout fontfile 
  393. say 'generated Malvern file ' fontfile
  394. return fontfile
  395.